home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / µSim 1.0.5 / source / DragManSim.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-23  |  7.8 KB  |  291 lines  |  [TEXT/CWIE]

  1. /*
  2. Copyright © 1993,1994,1995 Fabrizio Oddone
  3. ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
  4. This source code is distributed as freeware:
  5. you may copy, exchange, modify this code.
  6. You may include this code in any kind of application: freeware,
  7. shareware, or commercial, provided that full credits are given.
  8. You may not sell or distribute this code for profit.
  9. */
  10. #ifndef __DRAG__
  11. #include <Drag.h>
  12. #endif
  13.  
  14. #ifndef __FSPCOMPAT__
  15. #include <FSpCompat.h>
  16. #endif
  17.  
  18. #include    "CursorBalloon.h"
  19. #include    "FabWList.h"
  20. #include    "FabWmemman.h"
  21.  
  22. #include    "Assembler.h"
  23. #include    "DragManSim.h"
  24. #include    "Globals.h"
  25. #include    "myMemory.h"
  26.  
  27. typedef struct myglobptr {
  28.     Boolean    canAcceptDrag;
  29.     Boolean    inContent;
  30.     } GlobalsData, *GlobalsPtr;
  31.  
  32. GlobalsData        gmyGlobals;
  33.  
  34. static pascal OSErr MyTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
  35.                         void *handlerRefCon, DragReference theDrag);
  36. static Boolean IsMyTypeAvailable(WindowPtr theWindow, DragReference theDrag);
  37. static pascal OSErr MyReceiveHandler(WindowPtr theWindow, void *handlerRefCon,
  38.                         DragReference theDrag);
  39.  
  40.  
  41. /*
  42. OSErr MyInitDragManager(void)
  43. {
  44. OSErr    err;
  45.  
  46. err = InstallTrackingHandler(MyDefaultTrackingHandler, 0L, &myGlobals);
  47. if (err == noErr)
  48.     err = InstallReceiveHandler(MyDefaultReceiveHandler, 0L, &myGlobals);
  49.  
  50. return err;
  51. }
  52. */
  53.  
  54. OSErr MyInstallHWindow(WindowPtr theWindow)
  55. {
  56. FabWindowPtr    thefabw;
  57. OSErr       err;
  58.  
  59. if (thefabw = GetFabWindowPtr(theWindow)) {
  60.     thefabw->trackUPP = NewDragTrackingHandlerProc(MyTrackingHandler);
  61.     thefabw->recUPP = NewDragReceiveHandlerProc(MyReceiveHandler);
  62.     
  63.     if ((err = InstallTrackingHandler(thefabw->trackUPP, theWindow, &gmyGlobals)) == noErr) {
  64.         err = InstallReceiveHandler(thefabw->recUPP, theWindow, &gmyGlobals);
  65.         if (err)
  66.             RemoveTrackingHandler(thefabw->trackUPP, theWindow);
  67.         }
  68. //    else
  69. //        DebugStr("\pMyInstallHWindow error on InstallTrackingHandler");
  70.     }
  71. return err;
  72. }
  73.  
  74. void MyRemoveHWindow(WindowPtr theWindow)
  75. {
  76. FabWindowPtr    thefabw;
  77.  
  78. if (thefabw = GetFabWindowPtr(theWindow)) {
  79.     (void) RemoveTrackingHandler(thefabw->trackUPP, theWindow);
  80.     (void) RemoveReceiveHandler(thefabw->recUPP, theWindow);
  81.     if (thefabw->trackUPP) {
  82.         DisposeRoutineDescriptor(thefabw->trackUPP);
  83.         thefabw->trackUPP = nil;
  84.         }
  85.     if (thefabw->recUPP) {
  86.         DisposeRoutineDescriptor(thefabw->recUPP);
  87.         thefabw->recUPP = nil;
  88.         }
  89.     }
  90. }
  91.  
  92. pascal OSErr MyTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
  93.                         void *handlerRefCon, DragReference theDrag)
  94. {
  95. Rect    tempRect = {0, 0, 0, 0};
  96. GlobalsPtr        myGlobals = (GlobalsPtr) handlerRefCon;
  97. Point            mouse, localMouse;
  98. void (*theProc)(WindowPtr, RectPtr);
  99. DragAttributes    attributes;
  100. RgnHandle        hiliteRgn;
  101. FabWindowPtr    thefabw;
  102. OSErr    err;
  103.  
  104. if ((err = GetDragAttributes(theDrag, &attributes)) == noErr) {
  105.     switch(theMessage) {
  106. //        case dragTrackingEnterHandler:
  107. //            break;
  108.         case dragTrackingEnterWindow:
  109.             myGlobals->canAcceptDrag = IsMyTypeAvailable(theWindow, theDrag);
  110.             myGlobals->inContent = false;
  111.             break;
  112.         case dragTrackingInWindow:
  113.             if (myGlobals->canAcceptDrag) {
  114.                 if ((err = GetDragMouse(theDrag, &mouse, 0L)) == noErr) {
  115.                     localMouse = mouse;
  116.                     GlobalToLocal(&localMouse);
  117.                     if (attributes & dragHasLeftSenderWindow) {
  118.                         if (thefabw = GetFabWindowPtr(theWindow)) {
  119.                             theProc = thefabw->getDragHiliteRectProc;
  120.                             if (theProc)
  121.                                 theProc(theWindow, &tempRect);
  122.                             }
  123.                         if (PtInRect(localMouse, &tempRect)) {
  124.                             if (myGlobals->inContent == false) {
  125.                                 hiliteRgn = NewRgn();
  126.                                 if (hiliteRgn) {
  127.                                     //InsetRect(&tempRect, 1, 1);
  128.                                     RectRgn(hiliteRgn, &tempRect);
  129.                                     (void) ShowDragHilite(theDrag, hiliteRgn, true);
  130.                                     DisposeRgn(hiliteRgn);
  131.                                     }
  132.                                 myGlobals->inContent = true;
  133.                                 }
  134.                             }
  135.                         else {
  136.                             if (myGlobals->inContent) {
  137.                                 (void) HideDragHilite(theDrag);
  138.                                 myGlobals->inContent = false;
  139.                                 }
  140.                             }
  141.                         }
  142.                     }
  143.     //            MyTrackItemUnderMouse(localMouse, theWindow);
  144.                 }
  145.             break;
  146.         case dragTrackingLeaveWindow:
  147.             if (myGlobals->canAcceptDrag && myGlobals->inContent) {
  148.                 (void) HideDragHilite(theDrag);
  149.                 }
  150.             myGlobals->canAcceptDrag = false;
  151.             break;
  152. //        case dragTrackingLeaveHandler:
  153. //            break;
  154.         }
  155.     }
  156. return err;
  157. }
  158.  
  159. Boolean IsMyTypeAvailable(WindowRef theWindow, DragReference theDrag)
  160. {
  161. HFSFlavor        hfsData;
  162. PromiseHFSFlavor    phfsData;
  163. //HVolumeParam    mypb;
  164. FSSpec            copySpec;
  165. //HFSFlavor        *theData;
  166. //AliasHandle        tempFolder;
  167. Size            dataSize;
  168. //FlavorFlags        theFlags;
  169. ItemReference    theItem;
  170. unsigned short    items, index;
  171. OSErr            err;
  172. Boolean            targetFolder, isAnAlias;
  173. Boolean            retVal = true;
  174.  
  175.  
  176. if ((err = CountDragItems(theDrag, &items)) == noErr) {
  177.     for (index = 1; (index <= items) && retVal; index++) {
  178.         if ((err = GetDragItemReferenceNumber(theDrag, index, &theItem)) == noErr) {
  179. //            if ((err = GetFlavorFlags(theDrag, theItem, flavorTypeHFS, &theFlags)) == noErr)
  180.             dataSize = sizeof(PromiseHFSFlavor);
  181.             if (err = GetFlavorData(theDrag, theItem, flavorTypePromiseHFS, &phfsData, &dataSize, 0L)) {
  182.                 dataSize = sizeof(HFSFlavor);
  183.                 if (noErr == (err = GetFlavorData(theDrag, theItem, flavorTypeHFS, &hfsData, &dataSize, 0L))) {
  184.                     switch (hfsData.fileType) {
  185.                         case kFTY_REG:
  186.                             retVal = theWindow == gWPtr_Registers;
  187.                             break;
  188.                         case kFTY_RAM:
  189.                         case 'TEXT':
  190.                             retVal = theWindow == gWPtr_Disasm || theWindow == gWPtr_Dump;
  191.                             break;
  192.                         default:
  193.                             retVal = false;
  194.                         }
  195.                     if (retVal) {
  196.                         copySpec = hfsData.fileSpec;
  197.                         if (err = ResolveAliasFile(©Spec, true, &targetFolder, &isAnAlias))
  198.                             retVal = false;
  199.                         }
  200.                     }
  201.                 else
  202.                     retVal = false;
  203.                 }
  204. //                
  205. //            else
  206. //                retVal = false;
  207.             }
  208.         else
  209.             retVal = false;
  210.         }
  211.     }
  212. else
  213.     retVal = false;
  214. return retVal;
  215. }
  216.  
  217. pascal OSErr MyReceiveHandler(WindowPtr /*theWindow*/, void *handlerRefCon,
  218.                         DragReference theDrag)
  219. {
  220. GlobalsPtr        myGlobals = (GlobalsPtr) handlerRefCon;
  221. //HVolumeParam    mypb;
  222. HFSFlavor        hfsData;
  223. PromiseHFSFlavor    phfsData;
  224. FInfo    myInfo;
  225. FSSpec            copySpec;
  226. //AliasHandle        tempFolder;
  227. //Point            mouse;
  228. ItemReference    theItem;
  229. //FlavorFlags        theFlags;
  230. Size            dataSize;
  231. unsigned short    items, index;
  232. OSErr            err = noErr;
  233. Boolean            targetFolder, isAnAlias;
  234.  
  235. //if ((err = GetDragMouse(theDrag, &mouse, 0L)) == noErr) 
  236. if (myGlobals->canAcceptDrag && myGlobals->inContent) {
  237.     if ((err = CountDragItems(theDrag, &items)) == noErr) {
  238.         for (index = 1; (index <= items) && (err == noErr); index++) {
  239.             if ((err = GetDragItemReferenceNumber(theDrag, index, &theItem)) == noErr) {
  240. //                if ((err = GetFlavorFlags(theDrag, theItem, flavorTypeHFS, &theFlags)) == noErr) 
  241.                 dataSize = sizeof(PromiseHFSFlavor);
  242.                 if ((err = GetFlavorData(theDrag, theItem, flavorTypePromiseHFS, &phfsData, &dataSize, 0L)) == noErr) {
  243.                     dataSize = sizeof(FSSpec);
  244.                     hfsData.fileType = kContainerAliasType;
  245.                     err = GetFlavorData(theDrag, theItem, phfsData.promisedFlavor, &hfsData.fileSpec, &dataSize, 0L);
  246.                     }
  247.                 else {
  248.                     dataSize = sizeof(HFSFlavor);
  249.                     err = GetFlavorData(theDrag, theItem, flavorTypeHFS, &hfsData, &dataSize, 0L);
  250.                     }
  251.                 if (err == noErr) {
  252.                     copySpec = hfsData.fileSpec;
  253.                     if ((err = ResolveAliasFile(©Spec, true, &targetFolder, &isAnAlias)) == noErr) {
  254.                         if (targetFolder == false) {
  255.                             if ((err = FSpGetFInfoCompat(©Spec, &myInfo)) == noErr) {
  256.                                 switch (myInfo.fdType) {
  257.                                     case kFTY_REG:
  258.                                         err = OpenProcessorState(©Spec);
  259.                                         UnloadSeg(OpenProcessorState);
  260.                                         break;
  261.                                     case kFTY_RAM:
  262.                                         err = myOpenFile(©Spec, gMMemory, kSIZE_RAM);
  263.                                         UnloadSeg(myOpenFile);
  264.                                         break;
  265.                                     case 'TEXT':
  266.                                         err = myAsmFile(©Spec);
  267.                                         UnloadSeg(myAsmFile);
  268.                                         break;
  269.                                     default:
  270.                                         err = dragNotAcceptedErr;
  271.                                     }
  272.                                 }
  273.                             }
  274.                         else
  275.                             err = dragNotAcceptedErr;
  276.                         }
  277.                     }
  278. //                    
  279.                 }
  280.             }
  281.         }
  282.     }
  283. else
  284.     err = dragNotAcceptedErr;
  285.  
  286. if (err)
  287.     err = dragNotAcceptedErr;
  288. return err;
  289. }
  290.  
  291.